package com.lanou.myim.presenter;

import android.widget.Toast;

import com.lanou.myim.application.BaseApplication;
import com.lanou.myim.model.AddFriendsModel;
import com.lanou.myim.model.AddFriendsModelInterface;
import com.lanou.myim.ui.activity.AddFriendsActivityInterface;

/**
 * Created by dllo on 16/3/11.
 */
public class AddFriendsPresenter implements AddFriendsPresenterInterface{
    private AddFriendsModelInterface addFriendsModel;
    private AddFriendsActivityInterface addFriendsActivity;

    public AddFriendsPresenter(AddFriendsActivityInterface addFriendsActivity){
        this.addFriendsActivity = addFriendsActivity;
        addFriendsModel = new AddFriendsModel();

    }

    @Override
    public void searchFriend(String userName) {
        if (userName.length() == 0){
            Toast.makeText(BaseApplication.applicationContext, "用户名不能为空", Toast.LENGTH_SHORT).show();
        }else if (addFriendsModel.isRepeat(userName)){
            Toast.makeText(BaseApplication.applicationContext, "好友已存在", Toast.LENGTH_SHORT).show();
        }else {
            addFriendsActivity.showLayout(userName);
        }
    }

    @Override
    public void addFriend(String userName) {
        addFriendsModel.addFriend(userName,"呵呵");
        addFriendsActivity.dismissLayout();
    }
}
